#ifndef FRACTION_H
#define FRACTION_H

#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

class Fraction {
public:
    // 默认构造函数
    Fraction();

    // 接受两个整数作为参数的构造函数
    Fraction(int num, int denom);

    // 拷贝构造函数
    Fraction(const Fraction& other);

    // 算术运算符：+ - * /
    Fraction operator+(const Fraction& other) const;
    Fraction operator-(const Fraction& other) const;
    Fraction operator*(const Fraction& other) const;
    Fraction operator/(const Fraction& other) const;
    
    // 关系运算符：< <= == != >= >
    bool operator<(const Fraction& other) const;
    bool operator<=(const Fraction& other) const;
    bool operator==(const Fraction& other) const;
    bool operator!=(const Fraction& other) const;
    bool operator>=(const Fraction& other) const;
    bool operator>(const Fraction& other) const;

    // 转换为 double 类型
    operator double() const;

    // 转换为 string 类型
    string toStr() const;

    // 流的插入器和提取器
    friend ostream& operator<<(ostream& out, const Fraction& f);
    friend istream& operator>>(istream& in, Fraction& f);

    // 从有限小数字符串进行转换
    static Fraction fromDec(double dec);

private:
    int num;// 分子
    int denom;// 分母
    void simplify();// 化简分数
};

#endif